<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <base href="<%=basePath%>">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="static/css/H-ui.css" media="all">
    <link rel="stylesheet" href="static/layui/css/layui.css" media="all">
    <title>用户信息列表</title>
</head>
<body>

<div>
    <form id="userLF" action="" method="post">
    <div class="text-c mt-20">
        <div class="layui-input-inline" style="float: left;margin-left: 10px;">
            <a class="layui-btn layui-btn-normal" onclick="openInsertView();" >新增用户</a>
        </div>
        <div class="layui-input-inline">
            <input type="text" id="username" name="username"  style="width:200px" placeholder="请输入用户名" class="layui-input" >
        </div>
        <a class="layui-btn" onclick="findByUsername();">搜索</a>
    </div>

    <div class="mt-20">
        <table class="layui-table" style="table-layout:fixed;word-wrap:break-word;">
            <thead>
            <tr>
                <th style="text-align:center;">序号</th>
                <th style="text-align:center;">名字</th>
                <th style="text-align:center;">年龄</th>
                <th style="text-align:center;">性别</th>
                <th style="text-align:center;">用户名</th>
                <th style="text-align:center;">角色</th>
                <th style="text-align:center;">创建时间</th>
                <th style="text-align:center;">操作</th>
            </tr>
            </thead>
            <tbody>
            <!-- 遍历循环后台传来的数据 -->
            <c:forEach items="${list}" var="list">
            <tr>
                <td style="text-align:center;">${list.userId}</td>
                <td style="text-align:center;">${list.name}</td>
                <td style="text-align:center;">${list.age}</td>
                <td style="text-align:center;">${list.sex == 1 ? '男' : '女'}</td>
                <td style="text-align:center;">${list.username}</td>
                <td style="text-align:center;">${list.role.roleName}</td>
                <td style="text-align:center;">${list.createTime}</td>
                <td style="text-align:center;">

                    <!-- 放大镜的图标 &#xe615; -->
                    <a title="修改" style="text-decoration: none" onclick="openUpdateView(${list.userId});">
                        <i class="layui-icon"   style="font-size: 16px; color: #000000;">&#xe642;</i>
                    </a>
                    
                    <a title="删除" style="text-decoration: none" onclick="del(${list.userId});">
                        <i class="layui-icon"   style="font-size: 16px; color: #000000;">&#xe640;</i>
                    </a>

                </td>
            </tr>
            </c:forEach>
            </tbody>

        </table>
        <br>
    </div>
    </form>
</div>

<script type="text/javascript" src="static/js/jquery.min.js"></script>
<script type="text/javascript" src="static/layer/layer.js"></script>
<script src="static/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
// 必须放入layui所规范的元素结构，Form模块才会对起进行重置渲染
layui.use(['layer','element','laydate'], function(){
    var laydate = layui.laydate;
    var element = layui.element;
    var layer = layui.layer;

});

// 新增用户弹窗
function openInsertView(){
    layer.open({
        type: 2,
        title:'新增用户',
        closeBtn: 2,
        area: ['50%', '60%'],// 宽、高所占窗口比例
        shadeClose: true,
        shade: 0.5,
        anim: 2,
        content: 'views/user/user_insert.jsp'
      });
}

//删除用户
function del(id){
    layer.confirm('确定删除吗？',{icon: 3, title:'提示'},function(index){
        layer.close(index);
        $.post('user.do?mark=delete',{'id':id},function(result){
            layer.alert('删除成功',function(){
            	// 刷新当前页面
                window.location.reload();
            });
        });
  
    });
}

//更新用户弹窗
function openUpdateView(id){
    layer.open({
        type: 2,
        title:'更新用户',
        closeBtn: 2,
        area: ['50%', '60%'],// 宽、高所占窗口比例
        shadeClose: true,
        shade: 0.5,
        anim: 2,
        content: 'user.do?mark=openUpdateView&id='+id // 使用字符串拼接的方式传递用户的ID
      });
}

//根据用户名查找用户信息
function findByUsername(){
	var url = 'user.do?mark=findByUsername';
	// 替换form表单需要提交的url
	$('#userLF').attr('action',url);
	// 提交form表单
	$('#userLF').submit();
}
</script>
</body>

</html>

